package com.buaa.xxx0315;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

import java.io.IOException;

public class MusicService extends Service {
    private MediaPlayer player;
    public MusicService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        player = new MediaPlayer();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        int action = intent.getIntExtra("action",-1);
        switch (action) {
            case MainActivity.PLAY :
                player.reset();
                try {
                    player.setDataSource("/sdcard/mp3/a.mp3");
                    player.prepare();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                player.start();
                break;
            case MainActivity.PAUSE :
                player.pause();
                break;
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
